package test.administrator.example.com.mvptest1.list.demo;


import test.administrator.example.com.mvptest1.R;
import test.administrator.example.com.mvptest1.framework.lce.MvpLceView;
import test.administrator.example.com.mvptest1.framework.lce.impl.fragment.BaseRefreshLceFragment;
import test.administrator.example.com.mvptest1.list.base.adapter.BaseRefreshAdapter;
import test.administrator.example.com.mvptest1.list.demo.adapter.EssenceAdapter;
import test.administrator.example.com.mvptest1.list.demo.bean.PostModel;

/**
 * Created by thinkpad on 2018/8/1.
 */

public class MyListFragment extends BaseRefreshLceFragment<PostModel, MvpLceView<PostModel>, MyListPresenter> implements MvpLceView<PostModel> {

	//配置P层
	@Override
	public MyListPresenter createPresenter() {
		return new MyListPresenter(getActivity());
	}

	//配置布局文件
	@Override
	public int getContentView() {
		return R.layout.fragment_essence;
	}

	//初始化界面
	@Override
	public void initData() {
		loadData(false);
		setLceAnimator(new LoadingAnimator());
	}

	//配置Adapter
	@Override
	public BaseRefreshAdapter bindAdapter() {
		return new EssenceAdapter(getActivity());
	}

	//刷新数据->下拉刷新
	@Override
	public void refreshData(boolean isDownRefresh) {
		super.refreshData(isDownRefresh);
		loadData(true);
	}

	//绑定数据
	@Override
	public void bindData(PostModel model) {
		//super作用：框架内部封装了下拉刷新头部和上拉加载底部隐藏和显示逻辑(每一个功能模块都是重复)
		super.bindData(model);
		//6、更新Adapter->核心：更新ArrayList列表
		getAdapter().refreshAdapter(isDownRefresh(),model.getList(),model);
	}

	//加载数据
	@Override
	public void loadData(boolean pullToRefresh) {
		super.loadData(pullToRefresh);
		getPresenter().getEssenceList(EssenceAdapter.Type.Text.type, pullToRefresh);
	}

}
